package com.xyd.Servlet;

import com.xyd.Biz.CommodityBiz;
import com.xyd.Biz.Impl.CommodityBizImpl;
import com.xyd.Entity.Commodity;
import com.xyd.Util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/html/manage/RemoveCommodityServlet")
public class RemoveCommodityServlet extends HttpServlet {
    SqlSession session = null;

    public void init() {
        session = SqlSessionFactoryUtil.open();
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        CommodityBiz commodityBiz = new CommodityBizImpl();
        Commodity commodity = commodityBiz.SerachCommodityById(Integer.parseInt(id));
        int result = commodityBiz.removeProductClassById(commodity);
        if (result > 0) {
            request.getRequestDispatcher("ProductServlet").forward(request, response);
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
